<?php

	$id_producto = $_POST['producto'];
		
		if(isset($_POST['categoria']) && $_POST['categoria']!='-1'){
		$id_categoria = $_POST['categoria'];
		}else{
		$id_categoria = $_POST['id_categoria_opc'];		
		}
	
		if(isset($_POST['subcategoria']) && $_POST['subcategoria']!='-1'){
		$id_subcategoria = $_POST['subcategoria'];
		}else{
		$id_subcategoria = $_POST['id_subcategoria_opc'];		
		}
		
		//si viene de la lista
		if(isset($_POST['id_subnivel1_opc']) && $_POST['id_subnivel1_opc'] != ""){
			$id_subnivel1_opc = $_POST['id_subnivel1_opc'];
		}else{
			$id_subnivel1_opc = '';
			}
	
		require_once('../php/class/subnivel1.class.php');
		$oSubNivel1 = new subnivel1();
    $los_subniveles1 = @$oSubNivel1->buscar_por($id_producto,$id_categoria,$id_subcategoria);
    
        if($los_subniveles1==0){
            $lista_subnivel1 = "<select id='subnivel1' name='subnivel1'>";
            $lista_subnivel1 .= "<option value=-1 selected>no hay opciones</option>";
        }else{
            $lista_subnivel1 = "<select id='subnivel1' name='subnivel1' onchange='listar_subnivel2()';>";
            $lista_subnivel1 .= "<option value=-1 selected>Seleccione una</option>";
            
                for($i=0;$i<count($los_subniveles1['ID']);$i++){
                    
                    if($los_subniveles1['ID'][$i]==$id_subnivel1_opc){
                        $selected = "selected";
                    }else{
						$selected = "";    
						}
						
                    $lista_subnivel1 .= "<option value=".$los_subniveles1['ID'][$i]." ".$selected." >".$los_subniveles1['DESCRIPCION'][$i]." (".$los_subniveles1['DESCRIPCION_ADMIN'][$i].")</option>";
                    
                }
            $lista_subnivel1 .= "</select>";
        }
    
		
		$response = $lista_subnivel1;
        echo json_encode($response);
        exit();     
   
?>
